import router from './router'
import pinia from './stores/index'
import { useUserInfoStore } from '@/stores/userInfo'

// 实例化用户信息仓库
const userInfoStore = useUserInfoStore(pinia)

// 需要token验证的名单
const whiteList = ['/shopcart/cart', '/adminCenter']

// 全局前置导航守卫
router.beforeEach((to, from, next) => {
  const token = localStorage.getItem('token')
  if (token) {
    next()
  } else {
    // token 不存在
    if (whiteList.indexOf(to.path) !== -1) {
      // 在验证名单中
      next('/center')
    } else {
      // 不在验证名单中
      next()
    }
  }
})
